package com.lemon.smartsafetynew.ui.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.ApplicationInfo;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.data.app.DataUtil;
import com.lemon.smartsafety.entity.event.http.HttpCallbackEvent;
import com.lemon.smartsafety.entity.safe.company.BindNfcEvent;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.tag.BaseTAG;
import com.lemon.smartsafety.tag.DefaultCode;
import com.lemon.smartsafetynew.ui.activity.base.BaseActivity;
import com.lemon.smartsafety.ui.activity.safe.data.BuildingCheckItemBindNfcActivity;
import com.lemon.smartsafety.ui.fragment.MainFragment;
import com.lemon.smartsafetynew.ui.fragment.base.BaseFragment;
import com.lemon.smartsafety.utils.LogUtils;
import com.lemon.smartsafety.utils.app.HUDUtil;
import com.lemon.smartsafety.utils.app.UIHelper;
import com.lemon.smartsafety.utils.common.DoubleClickExitHelper;
import com.lemon.smartsafetynew.entity.User;
import com.lemon.smartsafetynew.entity.event.common.UserInfoRefreshEvent;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolBo;
import com.lemon.smartsafetynew.entity.patrol.SafePatrolTaskItemVo;
import com.lemon.smartsafetynew.net.services.AccountServices;
import com.lemon.smartsafetynew.net.services.SafePatrolServices;
import com.lemon.smartsafetynew.ui.activity.patrol.SafePatrolCheckItemActivity;
import com.lemon.smartsafetynew.ui.activity.qrcode.CodeUtils;
import com.lemon.smartsafetynew.ui.activity.qrcode.QRcodeActivity;
import com.lemon.smartsafetynew.util.common.AnimationUtils;
import com.lemon.smartsafetynew.util.common.AppSharePreferenceUtil;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.constants.SafeCloudConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;
import com.lemon.smartsafetynew.util.user.UserTypeUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;

public class MainNewActivity extends BaseActivity {

    public static final String TAG = "MainNewActivity";

    @Bind(R.id.main_layout)
    LinearLayout mainLayout;

    @Bind(R.id.work_layout)
    LinearLayout workLayout;

    @Bind(R.id.notice_layout)
    LinearLayout noticeLayout;

    @Bind(R.id.contact_layout)
    LinearLayout contactLayout;

    @Bind(R.id.me_layout)
    LinearLayout meLayout;

    @Bind(R.id.main_plus)
    ImageView mainPlus;

    private Toolbar toolbar;

    private BaseFragment mCurrentFragment;
    private DoubleClickExitHelper mDoubleClickExit;

    private int mCurrentDrawId;

    private Map<String, BaseFragment> mBaseFragmentMap = new HashMap<>();
    private Map<Integer, String> mDrawerIdMap;

    private User user;

    private int times = 0;                    //尝试3次都失败就下次再绑定
    private static final int THREE_TIMES = 3; //尝试3次都失败就下次再绑定

    @Override
    protected void initViews() {

        toolbar = getViewById(R.id.toolbar);
        toolbar.setVisibility(View.GONE);

//        toolbar = getViewById(R.id.toolbar);
//        toolbar.setContentInsetsAbsolute(0, 0);
//        setSupportActionBar(toolbar);

        getWindow().setBackgroundDrawable(null);

        //双击退出工具类
        mDoubleClickExit = new DoubleClickExitHelper(this);

        /*
        if (isActivate()) {  //账号已激活
            //初始化MainFragment
            initMainView();
        }
        */
        user = AccountUtil.getUser();
        if (user != null) {
            if (ApplicationInfo.PRODUCT_SUPPORT.equals(user.getUserType())) {
                initProductSupportView();
            } else {
                initMainView();
            }
        }

//        if (!AccountUtil.getJPushStatus()) {  //如果是false就需要绑定Jpush
//            bindJPush();
//        }

    }

    @Override
    protected void getBundleArgs() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_main_new;
    }

    /**
     * 监听返回--是否退出程序
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // 是否退出应用
            return mDoubleClickExit.onKeyDown(keyCode, event);
        }
        return super.onKeyDown(keyCode, event);
    }

    @OnClick({R.id.main_layout, R.id.work_layout, R.id.notice_layout, R.id.me_layout, R.id.contact_layout, R.id.main_plus})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.main_layout:

                disSelected(mCurrentDrawId);
                mCurrentDrawId = R.string.draw_home;
                select(mCurrentDrawId);

                break;
            case R.id.work_layout:

                disSelected(mCurrentDrawId);
                mCurrentDrawId = R.string.draw_work;
                select(mCurrentDrawId);


                break;
            case R.id.notice_layout:

                disSelected(mCurrentDrawId);
                mCurrentDrawId = R.string.draw_notice;
                select(mCurrentDrawId);

                break;

            case R.id.contact_layout:

                disSelected(mCurrentDrawId);
                mCurrentDrawId = R.string.draw_contact;
                select(mCurrentDrawId);

                break;

            case R.id.me_layout:

                disSelected(mCurrentDrawId);
                mCurrentDrawId = R.string.draw_me;
                select(mCurrentDrawId);

                break;

            case R.id.main_plus:

                popupWindow(mainPlus);
                break;
        }

        mCurrentFragment = getFragment(mDrawerIdMap.get(mCurrentDrawId));
        transactionSupportFragment(mCurrentFragment);
    }

    private void disSelected(int id) {
        switch (id) {
            case R.string.draw_home:
                mainLayout.getChildAt(0).setSelected(false);
                mainLayout.getChildAt(1).setSelected(false);
                break;
            case R.string.draw_work:
                workLayout.getChildAt(0).setSelected(false);
                workLayout.getChildAt(1).setSelected(false);
                break;
            case R.string.draw_notice:
                noticeLayout.getChildAt(0).setSelected(false);
                noticeLayout.getChildAt(1).setSelected(false);
                break;
            case R.string.draw_contact:
                contactLayout.getChildAt(0).setSelected(false);
                contactLayout.getChildAt(1).setSelected(false);
                break;
            case R.string.draw_me:
                meLayout.getChildAt(0).setSelected(false);
                meLayout.getChildAt(1).setSelected(false);
                break;
        }
    }

    private void select(int id) {
        switch (id) {
            case R.string.draw_home:
                mainLayout.getChildAt(0).setSelected(true);
                mainLayout.getChildAt(1).setSelected(true);
                break;
            case R.string.draw_work:
                workLayout.getChildAt(0).setSelected(true);
                workLayout.getChildAt(1).setSelected(true);
                break;
            case R.string.draw_notice:
                noticeLayout.getChildAt(0).setSelected(true);
                noticeLayout.getChildAt(1).setSelected(true);
                break;
            case R.string.draw_contact:
                contactLayout.getChildAt(0).setSelected(true);
                contactLayout.getChildAt(1).setSelected(true);
                break;
            case R.string.draw_me:
                meLayout.getChildAt(0).setSelected(true);
                meLayout.getChildAt(1).setSelected(true);
                break;
        }
    }

    private BaseFragment getFragment(String fragmentName) {
        BaseFragment baseFragment = mBaseFragmentMap.get(fragmentName);
        if (baseFragment == null) {
            try {
                baseFragment = (BaseFragment) Class.forName(fragmentName).newInstance();
            } catch (Exception e) {
                e.printStackTrace();
                baseFragment = MainFragment.newInstance();
            }
            mBaseFragmentMap.put(fragmentName, baseFragment);
        }
        return baseFragment;
    }

    private void transactionSupportFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.content_layout, fragment).commit();
    }

    // ========= 初始化主页面 ==========
    private void initMainView() {

        mDrawerIdMap = DataUtil.getListForMainActivity();
        mCurrentFragment = getFragment(mDrawerIdMap.get(R.string.draw_work));
        transactionSupportFragment(mCurrentFragment);
        mCurrentDrawId = R.string.draw_work;
        select(mCurrentDrawId);

    }

    /**
     * 初始化产品支持页面
     */
    private void initProductSupportView() {

        mainLayout.setVisibility(View.GONE);
        workLayout.setVisibility(View.GONE);
        noticeLayout.setVisibility(View.GONE);
        contactLayout.setVisibility(View.GONE);
        mainPlus.setVisibility(View.GONE);

        mDrawerIdMap = DataUtil.getListForMainActivity();
        mCurrentFragment = getFragment(mDrawerIdMap.get(R.string.draw_me));
        transactionSupportFragment(mCurrentFragment);
        mCurrentDrawId = R.string.draw_me;
        select(mCurrentDrawId);

    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMainThread(HttpCallbackEvent event) {

        if (KeyConstants.URL_UPDATE_USER_INFO.equals(event.getTag())) {                             //刷新UserInfo
            if (event.getHttpFlow() == HandlerCallback.HttpFlow.START) {
            } else if (event.getHttpFlow() == HandlerCallback.HttpFlow.FINISH) {
                if (event.getEventResult() == Constants.Result.SUCCESS) {

                    if (event.getObj() instanceof User) {
                        User user = (User) event.getObj();
                        AppSharePreferenceUtil.getInstance().putString(SafeCloudConstants.CURRENT_USER, mGson.toJson(user));
                        AppService.getBus().post(new UserInfoRefreshEvent());
                    }

                } else {

                }
            }
        } else if (KeyConstants.URL_GET_SAFE_PATROL_ITEM.equals(event.getTag())) {                  //获取检查项
            if (event.getHttpFlow() == HandlerCallback.HttpFlow.START) {
                mHUDUtil.showHUD();
            } else if (event.getHttpFlow() == HandlerCallback.HttpFlow.FINISH) {
                mHUDUtil.hidden();
                if (event.getEventResult() == Constants.Result.SUCCESS) {

                    if (event.getObj() instanceof SafePatrolTaskItemVo) {

                        SafePatrolTaskItemVo itemVo = (SafePatrolTaskItemVo) event.getObj();

                        if (SafePatrolBo.ItemType.self_check_point.getValue().equals(itemVo.getItem_type())) {
                            /**
                             * 企业风险点
                             */
                            if (UserTypeUtil.isGovType(AccountUtil.getUserType())) {
                                mHUDUtil.showErrorTip(getString(R.string.not_gov_check_item));
                            } else {
                                if (AccountUtil.getCompanyId().equals(itemVo.getCompany_id())) {
                                    /**
                                     * 跳转检查项详细的检查页面
                                     */
                                    Bundle bundle = new Bundle();
                                    bundle.putSerializable(KeyConstants.KEY_SAFE_PATROL_CHECK_ITEM_TASK, (SafePatrolTaskItemVo) event.getObj());
                                    bundle.putInt(KeyConstants.KEY_SAFE_PATROL_TASK_ID, 1);// task_id ：没有任何作用的   只是没时间修改原先的逻辑了，这里只是为了保持智慧安全云一样的页面传输结构，减少修改
                                    bundle.putString(KeyConstants.KEY_SAFE_PATROL_TASK_ID_NEW, "");// taskId 根据任务iD进行巡检
                                    UIHelper.showActivity(MainNewActivity.this, bundle, SafePatrolCheckItemActivity.class);

                                } else {
                                    mHUDUtil.showErrorTip(getString(R.string.not_your_check_item));
                                }
                            }
                        } else if (SafePatrolBo.ItemType.grid_check_point.getValue().equals(itemVo.getItem_type())) {

                            /**
                             * 政府网格点
                             */
                            if (UserTypeUtil.isGovType(AccountUtil.getUserType())) {
                                /**
                                 * 跳转检查项详细的检查页面
                                 */
                                Bundle bundle = new Bundle();
                                bundle.putSerializable(KeyConstants.KEY_SAFE_PATROL_CHECK_ITEM_TASK, (SafePatrolTaskItemVo) event.getObj());
                                bundle.putInt(KeyConstants.KEY_SAFE_PATROL_TASK_ID, 1);// task_id ：没有任何作用的   只是没时间修改原先的逻辑了，这里只是为了保持智慧安全云一样的页面传输结构，减少修改
                                bundle.putString(KeyConstants.KEY_SAFE_PATROL_TASK_ID_NEW, "");// taskId 根据任务iD进行巡检
                                UIHelper.showActivity(MainNewActivity.this, bundle, SafePatrolCheckItemActivity.class);
                            } else {
                                mHUDUtil.showErrorTip("网格检查点，您无法检查");
                            }
                        }

                    }

                } else {
                    mHUDUtil.showErrorTip(event.getMsg(), new HUDUtil.CallBack() {
                        @Override
                        public void onCall() {

                        }
                    });
                }
            }
        } else if (KeyConstants.URL_BIND_JPUSH.equals(event.getTag())) {                            //绑定JPush
            if (event.getHttpFlow() == HandlerCallback.HttpFlow.START) {
            } else if (event.getHttpFlow() == HandlerCallback.HttpFlow.FINISH) {
                if (event.getEventResult() == Constants.Result.SUCCESS) {
                    //保存JPush状态
                    AccountUtil.saveJPushStatus(true);
                } else {
                    times++;
                    if (times < THREE_TIMES) {  //3次尝试
                        bindJPush();
                    } else {
                        mHUDUtil.showErrorTip("推送服务激活失败", new HUDUtil.CallBack() {
                            @Override
                            public void onCall() {

                            }
                        });
                    }
                }
            }
        } else if (KeyConstants.URL_GET_ACCOUNT_USERS.equals(event.getTag())) {

            /**
             * 检查账号的用户组
             */
            if (event.getHttpFlow() == HandlerCallback.HttpFlow.START) {
            } else if (event.getHttpFlow() == HandlerCallback.HttpFlow.FINISH) {
                if (event.getEventResult() == Constants.Result.SUCCESS) {
                    AppSharePreferenceUtil.getInstance().putBoolean(SafeCloudConstants.MULTI_USER, true);
                } else {
                    AppSharePreferenceUtil.getInstance().putBoolean(SafeCloudConstants.MULTI_USER, false);
                }
            }

        }
    }


    @Override
    protected void onResume() {
        super.onResume();

        // ==== 获取UserInfo ====
        freshUserInfo();
    }


    /**
     * 刷新UserInfo
     */
    private void freshUserInfo() {
        // ==== 获取UserInfo ====
        if (AccountUtil.isLogin()) {
            User user = AccountUtil.getUser();
            if (user != null) {

                /**
                 * 刷新用户列表
                 */
                AccountServices.init().updateUserInfo(user.getToken());

                /**
                 * 获取账号用户组
                 */
                LemonRequestParams params = new LemonRequestParams("");
                params.put("user_id", AccountUtil.getUserID());
                AccountServices.init().getAccountUsers(params);
            }
        }

        /**
         * 如果是false就需要绑定Jpush
         */
        if (!AccountUtil.getJPushStatus()) {
            bindJPush();
        }
    }

    /**
     * 判断账号是否被企业绑定
     */
    private boolean isActivate() {

        /*
        User user = AccountUtil.getUser();

        if (user != null) {
            if (null == user.getStatus() || !("0".equals(user.getStatus()))) {
                showDialog("您的账号尚未绑定企业，请联系您的企业管理员绑定您的账号。");
                return false;
            } else {
                return true;
            }
        } else {
            MainNewActivity.this.finish();
            return false;
        }*/

        return true;
    }

    /**
     * Dialog
     */
    private MaterialDialog materialDialog;
    private MaterialDialog tipsDialog;

    private void showDialog(String remark) {
        materialDialog = new MaterialDialog.Builder(this)
                .title("提示")
                .content(remark)
                .positiveText(android.R.string.ok)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        MainNewActivity.this.finish();
                    }
                })
                .cancelable(false)
                .show();
    }

    private void cancelDialog() {

        if (materialDialog != null && materialDialog.isShowing()) {
            materialDialog.dismiss();
            materialDialog = null;
        }

        if (tipsDialog != null && tipsDialog.isShowing()) {
            tipsDialog.dismiss();
            tipsDialog = null;
        }
    }

    private void showPlusTips(String remark) {
        tipsDialog = new MaterialDialog.Builder(this)
                .title("提示")
                .content(remark)
                .positiveText(android.R.string.ok)
                .cancelable(false)
                .show();
    }

    /**
     * 清理对象，缓存等
     */
    private void clear() {
        cancelDialog();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        clear();
    }


    //============= 二维码和NFC ==============
    private PopupWindow popupWindow;
    private static final int DURATION_TIME = 300;
    private static final int DURATION_INTERVAL = 100;
    private static final int FIRST_ROW = 100;
    private static final float[] START_ROTATION = new float[]{0, 45};
    private static final float[] CLOSE_ROTATION = new float[]{45, 0};
    private float[] START_TRANSLATION_Y = null;

    private void popupWindow(View parent) {
        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(MainNewActivity.this).inflate(
                R.layout.layout_main_plus, null);

        popupWindow = new PopupWindow(contentView,
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);

        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));

        popupWindow.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });

        // 设置好参数之后再show
        popupWindow.showAtLocation(parent, Gravity.NO_GRAVITY, 0, 0);


        // ============= Listener =========
        final ImageView closeImageView = (ImageView) contentView.findViewById(R.id.close_image);
        final LinearLayout nfcLayout = (LinearLayout) contentView.findViewById(R.id.nfc_layout);
        final LinearLayout qrLayout = (LinearLayout) contentView.findViewById(R.id.qrcode_layout);

        float height = CommonUtil.convertDipOrPx(MainNewActivity.this, FIRST_ROW);
        START_TRANSLATION_Y = new float[]{height, -50, -25, -10, 0, -20, -10, 0};

        closeImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AnimationUtils.closeRotationAnimation(closeImageView, DURATION_TIME, CLOSE_ROTATION);
                AnimationUtils.closeAnimation(nfcLayout, DURATION_TIME, CommonUtil.convertDipOrPx(MainNewActivity.this, FIRST_ROW));
                AnimationUtils.closeAnimation(qrLayout, DURATION_TIME, CommonUtil.convertDipOrPx(MainNewActivity.this, FIRST_ROW));

                closeImageView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        popupWindow.dismiss();
                    }
                }, DURATION_TIME);

            }
        });

        nfcLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startNfc();
                //mHUDUtil.showInfoTip("暂未开放");
                popupWindow.dismiss();
            }
        });

        qrLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startQrcode();
                popupWindow.dismiss();
            }
        });

        // =========== 动画 ============
        AnimationUtils.startRotationAnimation(closeImageView, DURATION_TIME, START_ROTATION);
        AnimationUtils.startAnimation(nfcLayout, DURATION_TIME + DURATION_INTERVAL, START_TRANSLATION_Y);
        AnimationUtils.startAnimation(qrLayout, DURATION_TIME + 2 * DURATION_INTERVAL, START_TRANSLATION_Y);

    }

    /**
     * 跳转NFC 读取页面
     */
    private void startNfc() {
        Bundle bundle = new Bundle();
        bundle.putString(BaseTAG.COMMON_BASE_TAG, MainNewActivity.class.getName());
        UIHelper.showActivity(this, bundle, BuildingCheckItemBindNfcActivity.class);
    }


    /**
     * 跳转QR code 读取页面
     */
    private void startQrcode() {
        try {
            //Intent intent = new Intent(this, CaptureActivity.class);
            Intent intent = new Intent(this, QRcodeActivity.class);
            startActivityForResult(intent, DefaultCode.REQUEST_CODE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * QR code读取结果
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        /**
         * 处理二维码扫描结果
         */
        if (requestCode == DefaultCode.REQUEST_CODE) {
            //处理扫描结果（在界面上显示）
            if (null != data) {
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                    String result = bundle.getString(CodeUtils.RESULT_STRING);
                    LogUtils.LOGE("解析结果:" + result);

                    //TODO 请求二维码
                    String company_id = "";
                    if (AccountUtil.getCompanyId() == null) {
                        company_id = "";
                    } else {
                        company_id = AccountUtil.getCompanyId();
                    }

                    LemonRequestParams params = new LemonRequestParams("");
                    params.put("company_id", company_id);
                    params.put("qr_code", result);
                    params.put("nfc_code", "");

                    SafePatrolServices
                            .init()
                            .getSafePatrolItem(params);

                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                    mHUDUtil.showErrorTip("解析二维码失败");
                }
            }
        }

    }

    /**
     * NFC 读取结果
     */
    @Subscribe
    public void onEventMainThread(final BindNfcEvent event) {
        if (MainNewActivity.class.getName().equals(event.getTag())) {
            if (!com.lemon.smartsafety.utils.CommonUtil.strIsEmpty(event.getCode())) {
                LogUtils.LOGE("巡查NFC:" + event.getCode());

                //TODO 请求NFC
                String company_id = "";
                if (AccountUtil.getCompanyId() == null) {
                    company_id = "";
                } else {
                    company_id = AccountUtil.getCompanyId();
                }

                LemonRequestParams params = new LemonRequestParams("");
                params.put("company_id", company_id);
                params.put("qr_code", "");
                params.put("nfc_code", event.getCode());

                SafePatrolServices
                        .init()
                        .getSafePatrolItem(params);
            }
        }
    }

    /**
     * 绑定JPush服务
     */
    private void bindJPush() {

        try {
            LemonRequestParams params = new LemonRequestParams("");
            params.put("user_id", AccountUtil.getUserID());
            params.put("registration_id", JPushInterface.getRegistrationID(MainNewActivity.this));
            Log.i("lala",JPushInterface.getRegistrationID(MainNewActivity.this));
            AccountServices.init().bindJPush(params);

        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
